// ==UserScript==
// @name         CSDN/知乎/bilibili/简书
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  适配移动端 | 去除所有广告 | 任意文本复制 | 界面优化让阅读更轻松
// @author       WY
// @license      GPL-3.0 License
// @original-script https://greasyfork.org/scripts/412212 (c)X.I.U
// @run-at       document-body
// @match        https://*.zhihu.com/*
// @match        https://*.csdn.net/*
// @match        https://*.jianshu.com/*
// @match        https://*.bilibili.com/*
// @match        https://juejin.cn/*
// @grant        GM_addStyle
// @grant        GM_openInTab
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// @grant        GM_notification
// @grant        unsafeWindow
// @require      https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js
// @require      https://cdn.bootcdn.net/ajax/libs/jquery-cookie/1.4.0/jquery.cookie.js
// ==/UserScript==

let version = "1.0.0";
Script_setting();


var $$ = document.querySelectorAll.bind(document);

(function() {
    'use strict';

    var url = unsafeWindow.location.href;//document.location.host
    var mobile=/(Android|iPhone|iPad)/i.test(navigator.userAgent);

    if(url.indexOf('zhihu.com')!=-1)
    {
        //登录页跳转
        if(url == "https://www.zhihu.com/signin?next=%2F")
        {
            window.location.replace("https://www.zhihu.com/search?q=&type=content");
        }
        //首页热搜
        if(url == 'https://www.zhihu.com/search?q=&type=content')
        {
            GM_addStyle('#SearchMain {visibility:hidden !important}');
            unsafeWindow.setTimeout(function(){ Zihu_hot_in_home(); },0);
            unsafeWindow.setTimeout(function(){ Zihu_hot_in_home(); },100);
            unsafeWindow.setTimeout(function(){ Zihu_hot_in_home(); },1000);
            GM_addStyle('#SearchMain {visibility:visible !important}');
        }
        //知乎弹窗去除 ->
        GM_addStyle('.css-ysn1om{display:none !important}');//右上方登录提示
        GM_addStyle('.css-1ynzxqw,.css-1t53heo{display:none !important}');//右下方登录提示
        GM_addStyle('.Modal-wrapper{display:none !important}');//登录弹窗
        //该方法仅屏蔽首次登录弹窗，页面内点赞等操作后仍会提示。完全屏蔽请注释后使用（将无法查看对话详情）//
        unsafeWindow.onload = function(){
            if(url != 'https://www.zhihu.com/search?q=&type=content'){
                unsafeWindow.setTimeout(function(){
                    if(document.querySelector(".Modal-wrapper")){
                        document.querySelector(".Modal-wrapper").remove();
                    }
                    GM_addStyle('.Modal-wrapper{display:flex !important}');
                }, 100);
            }else{ GM_addStyle('.Modal-wrapper{display:flex !important}') }
        }
        //<-
        GM_addStyle('html{overflow:visible !important}');
        GM_addStyle('html{margin-right:auto !important}');
        GM_addStyle('.Question-mainColumnLogin{display:none !important}');//登录提示栏
        //GM_addStyle('.Sticky{display:none !important}');//右侧窗口
        GM_addStyle('.Card.AppBanner{display:none !important}');//右侧登录提示栏
        GM_addStyle('.Pc-card.Card{display:none !important}');//右侧广告

        GM_addStyle('.Pc-word {display:none !important}');//问答列表内广告

        GM_addStyle('.TheaterDetailDanmakuArea-footer {display:none !important}');//直播评论区下方下载按钮

        //一键简化
        Clean_zhihu();

        //mobile
        if(mobile){Mobile_zhihu();}
        GM_addStyle('.OpenInAppButton {display:none !important}');//删除打开app按钮(首页/移动端)


        //Pic 原图
        PIC_zhihu();

        //Seconde
        unsafeWindow.setTimeout(function(){ PIC_zhihu()},1000);

        //回答时间显示
        if(url.indexOf('https://www.zhihu.com/question')!=-1){Time_for_zhihu();}

        [].concat(...document.querySelectorAll("*")).map(item=>{//
            item.oncopy = function(e) {
                e.stopPropagation();
            }
        });
    }
    else if(url.indexOf('csdn.net')!=-1)
    {
        // 去除侧边栏广告
        GM_addStyle('#footerRightAds{display:none !important}');
        //CSDN登录弹窗去除 ->
        GM_addStyle('.passport-login-container {display:none !important}');//登录弹窗//收藏点赞订阅专栏将无反应
        GM_addStyle('#csdn-toolbar-profile-nologin {display:none !important}');//登录提示弹窗
        //<-
        //右侧悬浮导航栏广告
        GM_addStyle('.csdn-common-logo-advert{display:none !important}');
        // 去除右侧工具
		GM_addStyle('.csdn-side-toolbar{display:none !important}');
        GM_addStyle('#recommend-right{display:none !important}');

        //右侧缩放提示
        GM_addStyle('.leftPop{display:none !important}');
        //评论上方打赏
        GM_addStyle('.reward-box-new{display:none !important}');
        //评论上方广告
        GM_addStyle('#dmp_ad_58{display:none !important}');
        //展开代码块
        GM_addStyle('pre.set-code-hide{height:100% !important}');
        GM_addStyle('pre.set-code-hide .hide-preCode-box{display:none !important}');
        //展开评论
        GM_addStyle('.comment-list-box{max-height:none !important}');
        GM_addStyle('.opt-box.text-center{display:none !important}');
        //展开需关注博主文本
        GM_addStyle('#article_content{height:100% !important}');
        GM_addStyle('.hide-article-box.hide-article-pos.text-center{display:none !important}');
        //一键三连按钮
        GM_addStyle('#health-companies {display:none !important}');
        //评论抢沙发
        GM_addStyle('.comment-sofa-flag {display:none !important}');
        //分享海报按钮
        //GM_addStyle('#health-companies {display:none !important}');
        //博主商场
        GM_addStyle('#csdn-shop-window-top {display:none !important}');//top
        GM_addStyle('#csdn-shop-window {display:none !important}');//buttom
        //页面顶部广告
        GM_addStyle('.toolbar-advert {display:none !important}');
        //首页
        if(url.indexOf('https://www.csdn.net/')!=-1){
            GM_addStyle('#kp_box_ww9877 {display:none !important}');//横条广告
            GM_addStyle('#kp_box_www_swiper {display:none !important}');//‘头条’右侧广告
            GM_addStyle('.www-home-silde-top {display:none !important}');//右侧广告
            GM_addStyle('.so-questionnaire {display:none !important}');//自产自销投票
            GM_addStyle('.links {display:none !important}');//友链
            GM_addStyle('.ad_fullWidth {display:none !important}');//列表内广告
        }
        ///blog首页///
        if(url.indexOf('https://blog.csdn.net/')!=-1){
            GM_addStyle('.banner-ad-box {display:none !important}');//横条广告
        }
        ///下载页//
        GM_addStyle('.ads.mt-10 {display:none !important}');//图片广告

        //一键简化
        Clean_csdn();

        //mobile
        if(mobile){Mobile_csdn();}

        // 免登录复制
        GM_addStyle('#content_views pre code{user-select:text !important}');
        GM_addStyle('#content_views pre{user-select:text !important}');
        GM_addStyle('#content_views{user-select:text !important}');
        try{
            window.onload=function()
            {
                $("code").attr("onclick", "mdcp.copyCode(event)");
                // 免登录复制
                if($(".hljs-button").length > 0)
                {
                    $(".hljs-button").removeClass("signin");
                    $(".hljs-button").addClass("{2}");
                    $(".hljs-button").attr("data-title", "复制");
                    $(".hljs-button").attr("onclick", "hljs.copyCode(event)");
                }

                try{
                    unsafeWindow.csdn.copyright.init("", "", "");
                }catch(_err){}
            }
        }catch(err){
            $$('*').forEach(item=>{ item.oncopy = e => e.stopPropagation()});
        }
    }
    else if(url.indexOf('jianshu.com')!=-1)
    {
        //简书去除弹窗
        GM_addStyle('.-umr26{display:none !important}');
        GM_addStyle('._27yofX{display:none !important}');
        GM_addStyle('._1aCo37{display:none !important}');
        GM_addStyle('._1aCo37-mask{display:none !important}');

        GM_addStyle('body{ position: none !important}');
        GM_addStyle('body{width: auto !important}');
        GM_addStyle('body{overflow: auto !important}');
        GM_addStyle('._3JYrtj :nth-child(2) {display:none !important}');//app下载

        GM_addStyle('._19DgIp{display:none !important}');//<hr/>
        GM_addStyle('._16AzcO{display:none !important}');//扫描下载app
        GM_addStyle('._6S_NkV{display:none !important}');//扫描下载app
        GM_addStyle('.l8ZVfE{display:none !important}');//扫描下载app

        //自动展开全文
        GM_addStyle('._2rhmJa._2BJJ_f{height:100% !important}');
        GM_addStyle('._22e-Te._24jYYR{display:none !important}');

        //标题栏
        GM_addStyle('#web-nav-app-download-btn {display:none !important}');//标题栏下载APP按钮

        //
        GM_addStyle('#index-aside-download-qrbox{display:none !important}');//app下载
        GM_addStyle('._24FgOn2LX2uICAAvbCms63_0{display:none !important}');//广告
        GM_addStyle('._3Qa4dn5YlokOkxn6RsnEsL_0{display:none !important}');//抽奖
        GM_addStyle('.fa8byxiLG1y_kbW7CHjYk_0{display:none !important}');//右侧抽奖浮动窗口
        GM_addStyle('.self-flow-ad.clearfix{display:none !important}');//列表广告
        GM_addStyle('.commonclass{display:none !important}');//列表广告
        unsafeWindow.setTimeout(function(){
            if(document.querySelector(".col-xs-7"))
            {//强制删除右侧栏垃圾广告
                unsafeWindow.setTimeout(function(){document.querySelector(".col-xs-7").children[2].remove();document.querySelector(".fa8byxiLG1y_kbW7CHjYk_0").remove();}, 100);//广告
                unsafeWindow.setTimeout(function(){unsafeWindow.setInterval(function(){if(document.querySelector(".col-xs-7").childElementCount > 4){document.querySelector(".col-xs-7").children[2].remove()}else{clearInterval(this)}}, 100);});
            }
        }, 100);

        //专题页
        GM_addStyle('.col-xs-24.col-sm-7.col-sm-offset-1.aside {visibility:hidden !important}');//隐藏右侧栏
        unsafeWindow.onload=function(){//加载完后移除广告并重新显示右侧栏
            unsafeWindow.setTimeout(function(){if(document.querySelector(".col-xs-24.col-sm-7.col-sm-offset-1.aside")){document.querySelector(".col-xs-24.col-sm-7.col-sm-offset-1.aside").children[0].remove();document.querySelector(".col-xs-24.col-sm-7.col-sm-offset-1.aside").children[4].remove();}GM_addStyle('.col-xs-24.col-sm-7.col-sm-offset-1.aside {visibility:visible !important}');}, 0);
        }
        GM_addStyle('iframe {display:none !important}');

        //一键简化
        Clean_jianshu();

        if(mobile){Mobile_jianshu();}

        $$('*').forEach(item=>{ item.oncopy = e => e.stopPropagation()});
    }
    else if(url.indexOf('bilibili.com')!=-1)
    {
        //首页
        GM_addStyle('.login-panel-popover{display:none !important}');//新版toolbar登录弹窗
        //GM_addStyle('.unlogin-popover{display:none !important}');//旧版toolbar登录弹窗-将留有横线
        //GM_addStyle('.van-popover.van-popper{display:none !important}');//旧版toolbar登录弹窗-登录后无法获得焦点
        GM_addStyle('.login-tip{display:none !important}');//登录弹窗tip提示
        GM_addStyle('.banner-card.b-wrap{display:none !important}');//首页横条广告
        GM_addStyle('.eva-banner{display:none !important}');//新版首页横条广告
        GM_addStyle('.contact-help{display:none !important}');//首页联系客服
        GM_addStyle('.nav-link-ul{display:none !important}');//旧版下载app按钮
        if($('.bilifont.bili-icon_dingdao_xiazaiapp')){$('.bilifont.bili-icon_dingdao_xiazaiapp').parent().parent().css('display','none');GM_addStyle('.nav-link-ul{display:flex !important}');}//下载app按钮
        GM_addStyle('.download-entry{display:none !important}');//新版下载app按钮toolbar
        //番剧
        GM_addStyle('.gg-floor-module{display:none !important}');//首页横条广告
        //视频页
        GM_addStyle('#bannerAd{display:none !important}');//视频下方广告
        GM_addStyle('#activity_vote{display:none !important}');//视频下方活动推广
        GM_addStyle('.ad-report.video-card-ad-small{display:none !important}');//视频合集右侧弹幕列表视频选集间广告

        //手机端
        GM_addStyle('.launch-app-btn.home-float-openapp{display:none !important}');//首页打开APP
        GM_addStyle('.launch-app-btn.m-nav-openapp{display:none !important}');//首页下载APP
        GM_addStyle('.mplayer-widescreen-callapp{position:unset !important; z-index:unset !important; display:none !important; visibility:hidden !important}');//视频内打开APP
        GM_addStyle('.m-video2-awaken-btn{display:none !important}');//视频页视频下方打开app
        GM_addStyle('.launch-app-btn.m-float-openapp{display:none !important}');//视频页右侧浮动打开app
        GM_addStyle('.launch-app-btn.related-openapp{display:none !important}');//视频页底部打开app

        $$('*').forEach(item=>{ item.oncopy = e => e.stopPropagation()});
    }
    else if(url.indexOf('juejin.cn')!=-1)
    {
        GM_addStyle('.sidebar-block.banner-block{display:none !important}');//首页右侧广告
        GM_addStyle('.extension{display:none !important}');//底部广告

        document.oncopy = event => event.clipboardData.setData('text',window.getSelection(0).toString());
    }

})();


function Mobile_jianshu(){
    //首页 & (专题)
    GM_addStyle('.modal {display:none !important}');//去除首页引流app界面,直接进入首页
    GM_addStyle('.slogan {display:none !important}');//导航栏提示
    GM_addStyle('.header-download {display:none !important}');//导航栏下载按钮
    GM_addStyle('.index_call-app-btn {display:none !important}');//打开app提示按钮 //打开APP，看更多好文
    GM_addStyle('.note__flow__download {display:none !important}');//文章列表内 app内查看提示按钮
    //循环删除列表广告
    unsafeWindow.setTimeout(function(){
        var loop = unsafeWindow.setInterval(
            function(){
                if(document.querySelector(".flow-list-ul"))
                {
                    if(document.querySelector(".flow-list-ul").children[1])
                    {
                        if(document.querySelector(".flow-list-ul").children[1].children[1])
                        {
                            document.querySelector(".flow-list-ul").children[1].children[1].remove();
                        }else{
                            clearInterval(loop);
                        }
                    }else{
                        clearInterval(loop);
                    }
                }else{
                    clearInterval(loop);
                }
            }, 100
        )});
    GM_addStyle('#footer {display:none !important}');//footer
    //移除显示app下载,展开更多
    GM_addStyle('.wrapper-kBteQ_0 {display:none !important}');//隐藏展开更多弹窗
    //展开更多hook
    unsafeWindow.setTimeout(function(){ $(".logo-wrap").click(function(){window.location.replace("https://www.jianshu.com/");}) },1000);//解决bug #BUG001 =》 因为官方未刷新页面策略导致，添加刷新策略
    unsafeWindow.setTimeout(function(){ $$('.flow-list-placeholder-load-more').forEach(item=>{ item.onclick = e => {
        $(".dialog-1f6iY_0").removeClass();document.querySelector(".cancel").click();}}); },1000);

    /*//去除文章顶部和底部广告
    var wphad_loop = unsafeWindow.setInterval(function() {
        var wph_ad = document.querySelector('div[aria-label="wph-ad"]');
        if (wph_ad) {
            wph_ad.remove();
            //clearInterval(wphad_loop);
        }
    }, 1000);*///不起作用待修复

    //文章页
    GM_addStyle('.call-app-btn {display:none !important}');//打开app提示按钮 //打开APP，看更多好文
    GM_addStyle('.download-app-guidance {display:none !important}');//打开app继续浏览内容底部弹窗//部分机型
    GM_addStyle('.app-open {display:none !important}');//时间侧边打开App按钮
    GM_addStyle('.wrapper-21Vwf_0 {display:none !important}');//文章内广告
    GM_addStyle('.line-container {display:none !important}');//诱导点赞文本
    //展开全文
    GM_addStyle('.collapse-free-content {position:static !important; height:100% !important; overflow:visible !important; padding-left:0 !important;padding-right:0 !important;margin-left:0 !important;margin-right:0 !important;}');
    GM_addStyle('.collapse-free-content:after { content:normal !important; position:static !important; left:auto !important; bottom:auto !important;width:auto !important;height:auto !important;}');
    GM_addStyle('.collapse-tips {display:none !important}');//删除展开全文按钮
    unsafeWindow.setTimeout(function(){ if($(".note").children().length == 6){$(".note").children(':last-child').remove()} },500); unsafeWindow.setTimeout(function(){ if($(".note").children().length == 6){$(".note").children(':last-child').remove()} },2500);//文章底部唯品会广告

    GM_addStyle('.comment-open-app-btn-wrap {display:none !important}');//诱导打开App，查看全部评论
    GM_addStyle('.more {display:none !important}');//更多精彩内容
    GM_addStyle('.recommend-wrap.recommend-ad {display:none !important}');//更多精彩内容
    GM_addStyle('.wrapper-_PVsE_0 {display:none !important}');//底部谷歌广告

    //小说文章页
    unsafeWindow.setTimeout(function(){ $(".book").children(':last-child').remove() },1000);//文章底部唯品会广告
    unsafeWindow.setTimeout(function(){ $(".book-info").click(function(){window.location.replace($(".book-info").attr('href'));}) },1000);//解决bug #BUG001 =》 因为官方未刷新页面策略导致，添加刷新策略
}


function Mobile_zhihu(){
    //专栏
    if(location.host.startsWith('zhuanlan')){
        SetUA("iphone");
        GM_addStyle('.Post-Button-ViewMore {display:none !important}');///查看更多/文字
        GM_addStyle('.css-9zqjc3-CommentContent {-webkit-line-clamp:unset !important}');//完整显示
        unsafeWindow.setTimeout(function(){
            if(document.querySelector(".Post-Sub")){ document.querySelector(".Post-Sub").onclick = function(e){ e.stopPropagation() } }
            if(document.querySelector(".css-qbubgm")){document.querySelector(".css-qbubgm").onclick = function(e){
                var ZL_pl = document.querySelector(".css-18nrxkn-PreviewCommentContent");
                if(ZL_pl){
                    ZL_pl.scrollIntoView({
                        behavior: "smooth", // 定义动画过渡效果， "auto"或 "smooth" 之一。默认为 "auto"
                        //block: "center", // 定义垂直方向的对齐， "start", "center", "end", 或 "nearest"之一。默认为 "start"
                        //inline: "nearest" // 定义水平方向的对齐， "start", "center", "end", 或 "nearest"之一。默认为 "nearest"
                    });//跳转评论
                }
            }}
        },1000);
    }else{SetUA("iPad")}

    //首页
    GM_addStyle('.MobileAppHeader-downloadLink {display:none !important}');//导航栏下载app
    GM_addStyle('.MobileAppHeader-authLink {display:none !important}');//导航栏注册登录
    GM_addStyle('.MobileAppHeader-searchBoxWithUnlogin {width: 70% !important}');//搜索框拉长
    GM_addStyle('.OpenInAppButton {display:none !important}');//打开app按钮
    //GM_addStyle('.DownloadGuide--downloadButton {display:none !important}');//下载app按钮 ->
    //更改为登录按钮
    var url = unsafeWindow.location.href;
    if(url == "https://www.zhihu.com/" || url.indexOf("https://www.zhihu.com/?utm_source=zhihu")!=-1){
        unsafeWindow.onload = function(){
            if(document.querySelector(".DownloadGuide--downloadButton")){
                var login_button = document.querySelector(".DownloadGuide--downloadButton").querySelector("a");
                login_button.text = "登录";
                login_button.href = "https://www.zhihu.com/signin?next=https://www.zhihu.com/";
            }
        }
    }
    //<-
    //导航栏添加搜索框
    if(url != "https://www.zhihu.com/search?type=content&q="){
        var input = document.createElement('input');
        input.type = "search"; input.className = "Input"; input.placeholder="搜索"; input.value="";
        var searchBox = document.createElement('label');
        searchBox.className = "MobileAppHeader-searchBox MobileAppHeader-searchBoxWithUnlogin Input-wrapper";
        var path = document.createElement('path');
        path.setAttribute("d", "M 17.068 15.58 a 8.377 8.377 0 0 0 1.774 -5.159 a 8.421 8.421 0 1 0 -8.42 8.421 a 8.38 8.38 0 0 0 5.158 -1.774 l 3.879 3.88 c 0.957 0.573 2.131 -0.464 1.488 -1.49 l -3.879 -3.878 Z m -6.647 1.157 a 6.323 6.323 0 0 1 -6.316 -6.316 a 6.323 6.323 0 0 1 6.316 -6.316 a 6.323 6.323 0 0 1 6.316 6.316 a 6.323 6.323 0 0 1 -6.316 6.316 Z");
        path.setAttribute("fill-rule","evenodd");
        var svg = document.createElement('svg');
        svg.setAttribute("class","Zi Zi--Search");
        svg.setAttribute("fill","#999");
        svg.setAttribute("viewBox","0 0 24 24");
        svg.setAttribute("width","18");
        svg.setAttribute("height","18");
        svg.append(path);
        searchBox.append(svg);
        searchBox.append(input);
        unsafeWindow.setTimeout(function(){ if(document.querySelector(".MobileAppHeader-inner")){document.querySelector(".MobileAppHeader-inner").append(searchBox)}},100);
        unsafeWindow.setTimeout(function(){ if(document.querySelector(".MobileAppHeader-inner")){document.querySelector(".MobileAppHeader-inner").append(searchBox)}},1000);
        searchBox.onclick = function(){
            window.location.replace("https://www.zhihu.com/search?type=content&q=");
        }}else{//搜索框点击仍有问题，BUG 002
            if(document.querySelector(".Input")){
                unsafeWindow.setTimeout(function(){ document.querySelector(".Input").focus();},1000);
            }
            document.querySelector(".Input").focus();
        }//END BUG 002

    //文章详情页
    GM_addStyle('.MBannerAd {display:none !important}');//文章底部广告
    GM_addStyle('.Card.RelatedReadings{display:none !important}');//文章底部广告
    GM_addStyle('.MHotFeedAd{display:none !important}');//热门推荐列表广告
    GM_addStyle('.HotQuestions-bottomButton{display:none !important}');//底部打开app
    //评论间距修复
    GM_addStyle('.Modal-content.css-1svde17 {padding: 5px !important}');//padding
    GM_addStyle('.Modal-content.css-1svde17 {width: 54% !important}');//width
    GM_addStyle('.Button.css-1x9te0t {left: -20px !important; top: 45px !important}');//close
    GM_addStyle('.Button.css-1x9te0t svg {fill:currentColor !important; color:#999999 !important}');//close
}


function Mobile_csdn(){
    SetUA("iphone"); //无效
    //首页
    GM_addStyle('#loginTag {display:none !important}');//导航栏注册登录
    GM_addStyle('.feed-Sign-span {display: none !important}');//打开app按钮
    GM_addStyle('.search_box {width: 220px !important}');//搜索框拉长

    //文章详情页
    GM_addStyle('.weixin-shadowbox.wap-shadowbox {display:none !important}');//诱导下载并打开APP弹窗(全屏)
    GM_addStyle('.feed-Sign-span {display:none !important}');//app打开按钮
    GM_addStyle('#loginTag {display:none !important}');//导航栏登录
    GM_addStyle('.btn_open_app_prompt_div{display:none !important}');//打开app按钮
    GM_addStyle('.readall_box{display:none !important}');//完全显示文章
    GM_addStyle('.article_content{overflow:visible !important; height:auto !important;}');//完全显示文章
    GM_addStyle('.view_comment_box{display:none !important}');//app打开按钮
    GM_addStyle('#first_recommend_list{display:none !important}');//去除最先推荐
    //GM_addStyle('.flag{display:none !important}');//去除浏览器打开字样

    //底部广告
    GM_addStyle('.add-firstAd {display: none !important}');//文章底部广告

    //点击评论按钮跳转评论区
    unsafeWindow.setTimeout(function(){
        var comment_button = $("span.have_count");
        comment_button.unbind("click");//解绑
        comment_button.on("click", function(){
            document.querySelector('#comment').scrollIntoView({
                behavior: "smooth", // 定义动画过渡效果， "auto"或 "smooth" 之一。默认为 "auto"
                //block: "center", // 定义垂直方向的对齐， "start", "center", "end", 或 "nearest"之一。默认为 "start"
                //inline: "nearest" // 定义水平方向的对齐， "start", "center", "end", 或 "nearest"之一。默认为 "nearest"
            });
        });//重绑
    },1000);
    //<--未解决！！！！！！

    //优化相关推荐-免跳转下载app-推荐分类
    Mobile_csdn_Recommend();
}

function Mobile_csdn_Recommend(){
    //暂时无效   $(".recommend-jump-app").unbind();//解绑下载APP事件
}


//简化CSDN, 提升阅读体验
function Clean_csdn(){
    var mobile=/(Android|iPhone|iPad)/i.test(navigator.userAgent);
    if(mobile){return;}//移动端无需简化页面

    var url = unsafeWindow.location.href;
    var re_article_details = /https:\/\/(.*)blog.csdn.net\/(\w*)(\/*)article\/details\/(\w+)/;
    var re_blog_home = /(^https:\/\/(\w*).blog.csdn.net\/$)|(^https:\/\/blog.csdn.net\/(\w\/*)((?!article\/details).)+$)/;

    if (GM_getValue("menu_GAEEScript_tc_CSDN")) {

        // 简化CSDN-简化文章详情页
        if(url.match(re_article_details)){
            GM_addStyle('.blog_container_aside {display:none !important}');///隐藏侧边栏
            GM_addStyle('.template-box {display:none !important}');
            GM_addStyle('#copyright-box {display:none !important}');

            // 调整主页面大小
            document.querySelector('#mainBox').style.width='98%';
            document.getElementsByTagName('main')[0].style.width='98%'
        }
        //简化个人博客页
        else if(url.match(re_blog_home)){
            GM_addStyle('.csdn-side-toolbar {display:none !important}');///隐藏侧边栏
            GM_addStyle('.blog_container_aside {display:none !important}');///隐藏侧边栏
        }
    }
}

//简化知乎
function Clean_zhihu(){
    if(GM_getValue("menu_GAEEScript_tc_Zhihu")){
        GM_addStyle('.Question-sideColumn {display:none !important}');
        GM_addStyle('.Question-mainColumn {width:1000px !important}');

        GM_addStyle('.AuthorInfo.AnswerItem-authorInfo.AnswerItem-authorInfo--related {max-width: unset !important}');
    }

    // 去除底部
    GM_addStyle('.Recommendations-Main {display:none !important}');
}

//简化简书
function Clean_jianshu(){
    if(GM_getValue("menu_GAEEScript_tc_Jianshu")){
        GM_addStyle('._2OwGUo {display:none !important}');
        GM_addStyle('._gp-ck {width:1000px !important}');//宽屏
    }
}


function Zihu_hot_in_home(){
    GM_addStyle('.Button.EmptyView-button {display:none !important}');//删除提问按钮
    var left_List = document.querySelector(".List");
    var zh_hot = document.querySelector("#zh_hot");
    if(!left_List){return}
    if(zh_hot){return}

    unsafeWindow.setTimeout(function(){
        var Tip = document.querySelector(".EmptyView-content");//
        if(Tip){ Tip.children[0].textContent="没有更多内容了~" }
    },2000);

    var hot = document.createElement('iframe');
    hot.setAttribute("src","https://www.zhihu.com/billboard");
    hot.setAttribute("id","zh_hot");
    hot.setAttribute("scrolling","no");
    hot.setAttribute("frameborder","0");
    hot.setAttribute("width","100%");
    hot.setAttribute("height","4800px");
    left_List.insertBefore(hot,left_List.childNodes[0]);

    unsafeWindow.setTimeout(function(){
        Array.from(document.querySelector("#zh_hot").contentDocument.querySelectorAll(".HotList-item")).forEach( item => {
            item.style.cssText = "-webkit-user-select: none !important;-moz-user-select: none !important;-o-user-select: none !important;user-select: none !important";
            item.onclick = function(e){
                unsafeWindow.setTimeout(function(){
                    var link = document.querySelector("#zh_hot").contentWindow.location.href; 
                    window.location.replace(link);//原页面打开链接
                    //window.open(link);//新标签页打开链接//有问题!未解决
                },350);
            }
        });
    },1000);
}

function PIC_zhihu(){
    Array.from(document.getElementsByTagName('img')).forEach(item => {
        if(item.getAttribute('data-original') != undefined && item.className != 'comment_sticker'){
            if (item.getAttribute('src') != item.getAttribute('data-original')) {
                item.setAttribute('src', item.getAttribute('data-original'));
            }
        }
    });
}



//知乎显示回答时间
function Time_for_zhihu(){
    // 完整显示时间 + 置顶显示时间 - 首页
    function topTime_index() {
        let topTime = document.querySelectorAll('.TopstoryItem');if (!topTime) return;
        topTime.forEach(function(_this) {
            let ContentItemTime = _this.querySelector('.ContentItem-time');if (!ContentItemTime) return;
            if (!(ContentItemTime.classList.contains('full')) && ContentItemTime.querySelector('span') && ContentItemTime.querySelector('span').innerText != null) {
                // 完整显示时间
                topTime_allTime(ContentItemTime);
                // 发布时间置顶
                topTime_publishTop(ContentItemTime, _this, 'ContentItem-meta');
            }
        });
    }// 完整显示时间 + 置顶显示时间 - 回答页
    function topTime_question() {
        let topTime = document.querySelectorAll('.ContentItem.AnswerItem');if (!topTime) return;
        topTime.forEach(function(_this) {
            let ContentItemTime = _this.querySelector('.ContentItem-time');if (!ContentItemTime) return;
            if (!(ContentItemTime.classList.contains('full')) && ContentItemTime.querySelector('span') && ContentItemTime.querySelector('span').innerText != null) {
                // 完整显示时间
                topTime_allTime(ContentItemTime);
                // 发布时间置顶
                topTime_publishTop(ContentItemTime, _this, 'ContentItem-meta');
            }

        });// 问题创建时间
        if (!(document.querySelector('.QuestionPage .QuestionHeader-side p')) && window.location.href.indexOf("log") == -1) { // 没有执行过 且 非问题日志页
            let createtime = document.querySelector('.QuestionPage>[itemprop~=dateCreated]').getAttribute('content');
            let modifiedtime = document.querySelector('.QuestionPage>[itemprop~=dateModified]').getAttribute('content');
            createtime = getUTC8(new Date(createtime));
            modifiedtime = getUTC8(new Date(modifiedtime));
            // 添加到问题页右上角
            document.querySelector('.QuestionPage .QuestionHeader-side').insertAdjacentHTML('beforeEnd', '<div style=\"color:#8590a6; margin-top:15px\"><p>创建时间:&nbsp;&nbsp;' + createtime + '</p><p>最后编辑:&nbsp;&nbsp;' + modifiedtime + '</p></div>');
        }
    }// 完整显示时间 + 置顶显示时间 - 搜索结果页
    function topTime_search() {
        let topTime = document.querySelectorAll('.ContentItem.AnswerItem, .ContentItem.ArticleItem');if (!topTime) return;
        topTime.forEach(function(_this) {
            let ContentItemTime = _this.querySelector('.ContentItem-time');if (!ContentItemTime) return;
            if (!(ContentItemTime.classList.contains('full')) && ContentItemTime.querySelector('span') && ContentItemTime.querySelector('span').innerText != null) {
                // 完整显示时间
                topTime_allTime(ContentItemTime);
                // 发布时间置顶
                topTime_publishTop(ContentItemTime, _this, 'SearchItem-meta');
            }
        });
    }// 完整显示时间 + 置顶显示时间 - 用户主页
    function topTime_people() {
        let topTime = document.querySelectorAll('.ContentItem.AnswerItem, .ContentItem.ArticleItem');if (!topTime) return;
        topTime.forEach(function(_this) {
            let ContentItemTime = _this.querySelector('.ContentItem-time');if (!ContentItemTime) return;
            if (!(ContentItemTime.classList.contains('full')) && ContentItemTime.querySelector('span') && ContentItemTime.querySelector('span').innerText != null) {
                // 完整显示时间
                topTime_allTime(ContentItemTime);
                // 发布时间置顶
                topTime_publishTop(ContentItemTime, _this, 'ContentItem-meta');
            }

        });
    }// 完整显示时间 + 置顶显示时间 - 专栏/文章
    function topTime_zhuanlan() {
        let ContentItemTime = document.querySelector('.ContentItem-time');if (!ContentItemTime) return;
        // 完整显示时间
        if (ContentItemTime.innerText.indexOf('编辑于') > -1 && !(ContentItemTime.classList.contains('doneeeeee'))) {
            let bianjiyu = ContentItemTime.innerText;
            ContentItemTime.click();
            ContentItemTime.innerText = (ContentItemTime.innerText + "，" + bianjiyu);
            ContentItemTime.classList.add("doneeeeee");
        }//发布时间置顶
        if (!(document.querySelector('.Post-Header > .ContentItem-time')) && !(document.querySelector('.ContentItem-meta > .ContentItem-time'))) {
            ContentItemTime.style.cssText = 'padding:0px 0px 0px 0px; margin-top: 14px';
            let temp_time = ContentItemTime.cloneNode(true);
            // ContentItemTime.style.display = 'none';
            if (window.location.href.indexOf("column") > -1){
                document.querySelector('.ContentItem-meta').insertAdjacentElement('beforeEnd', temp_time);
            } else {
                document.querySelector('.Post-Header').insertAdjacentElement('beforeEnd', temp_time);
            }
        }
    }// 完整显示时间
    function topTime_allTime(ContentItemTime) {
        if (ContentItemTime.innerText.indexOf("发布于") == -1 && ContentItemTime.innerText.indexOf("编辑于") > -1) { //只有 "编辑于" 时增加具体发布时间 data-tooltip
            let data_tooltip = ContentItemTime.querySelector('span').getAttribute('data-tooltip');
            let oldtext = ContentItemTime.querySelector('span').innerText;
            ContentItemTime.querySelector('span').innerText = data_tooltip + "，" + oldtext;
            ContentItemTime.classList.add('full');
        } else if (ContentItemTime.innerText.indexOf("发布于") > -1 && ContentItemTime.innerText.indexOf("编辑于") == -1) { //只有 "发布于" 时替换为具体发布时间 data-tooltip
            let data_tooltip = ContentItemTime.querySelector('span').getAttribute('data-tooltip');
            ContentItemTime.querySelector('span').innerText = data_tooltip;
            ContentItemTime.classList.add('full');
        }
    }// 发布时间置顶
    function topTime_publishTop(ContentItemTime, _this, class_) {
        if (!ContentItemTime.parentNode.classList.contains(class_)) {
            let temp_time = ContentItemTime.cloneNode(true);
            //_this.querySelector('.RichContent .ContentItem-time').style.display = 'none';
            _this.querySelector('.' + class_).insertAdjacentElement('beforeEnd', temp_time);
        }
    }// UTC 标准时转 UTC+8 北京时间，来自：https://greasyfork.org/zh-CN/scripts/402808
    function getUTC8(datetime) {
        let month = (datetime.getMonth() + 1) < 10 ? "0" + (datetime.getMonth() + 1) : (datetime.getMonth() + 1);
        let date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
        let hours = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
        let minutes = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
        let seconds = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
        return (datetime.getFullYear() + "-" + month + "-" + date + "\xa0\xa0" + hours + ":" + minutes + ":" + seconds);
    }
    unsafeWindow.onload = function(){
        unsafeWindow.setTimeout(function(){if(document.querySelector(".Modal-wrapper")){document.querySelector(".Modal-wrapper").remove();}
                                           GM_addStyle('.Modal-wrapper{display:flex !important}');}, 100);

        unsafeWindow.setInterval(function() {
            try{
                topTime_question();
            }catch(err) {
                
            }
        }, 300);
    }
}

function SetUA(phone){
    var UA;
    if(phone == "iphone"){
        UA = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1";
    }
    if(phone == "iPad"){
        UA = "Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1";
    }

    Object.defineProperties(navigator,{
        userAgent:{value:UA},
        platform:{value:'Mac'}
    });
}


function Script_setting(){
    var menu_ALL = [
        ['menu_GAEEScript_tc_CSDN', 'CSDN', 'CSDN宽屏/简化', true],
        ['menu_GAEEScript_tc_Zhihu', 'Zhihu', '知乎宽屏/简化', true],
        ['menu_GAEEScript_tc_Jianshu', 'Jianshu', '简书宽屏/简化', true],
    ], menu_ID = [];
    for (let i=0;i<menu_ALL.length;i++){ // 如果读取到的值为 null 就写入默认值
        if (GM_getValue(menu_ALL[i][0]) == null){GM_setValue(menu_ALL[i][0], menu_ALL[i][3])};
    }
    registerMenuCommand();

    // 注册脚本菜单
    function registerMenuCommand() {
        if (menu_ID.length > menu_ALL.length){ // 如果菜单ID数组多于菜单数组，说明不是首次添加菜单，需要卸载所有脚本菜单
            for (let i=0;i<menu_ID.length;i++){
                GM_unregisterMenuCommand(menu_ID[i]);
            }
        }
        for (let i=0;i<menu_ALL.length;i++){ // 循环注册脚本菜单
            menu_ALL[i][3] = GM_getValue(menu_ALL[i][0]);
            menu_ID[i] = GM_registerMenuCommand(`${menu_ALL[i][3]?'✅':'❎'} ${menu_ALL[i][2]}`, function(){menu_switch(`${menu_ALL[i][0]}`,`${menu_ALL[i][1]}`,`${menu_ALL[i][2]}`,`${menu_ALL[i][3]}`)});
        }
    }

    //切换选项
    function menu_switch(name,ename,cname,value){
        if(value == 'false'){            
            GM_setValue(`${name}`, true);
            registerMenuCommand(); // 重新注册脚本菜单
            location.reload(); // 刷新网页
            GM_notification({text: `「${cname}」已开启\n`, timeout: 3500}); // 提示消息
        }else{            
            GM_setValue(`${name}`, false);
            registerMenuCommand(); // 重新注册脚本菜单
            location.reload(); // 刷新网页
            GM_notification({text: `「${cname}」已关闭\n`, timeout: 3500}); // 提示消息
        }
        registerMenuCommand(); // 重新注册脚本菜单
    }
}
